#pragma once
#include "common.h"
#include "../gui/mainwindow.h"
#include "../mapobjects/objectstorage.h"
#include "../mapobjects/geometry.h"
#include <QtCore/QObject>

class GraphBuilder: public QObject
{
Q_OBJECT
protected slots:
    void onClickEvent (const QPointF&);
	void onMapLoaded  ();
public:
    void init(Viewer* viewer);
    void addLine(const QLineF& line, list<QLineF>& lines);
private:
    Viewer* viewer;
    vector<vector<size_t>> graph;
    vector<QPointF> points;
    vector<QPointF> path;
    int startIndex;
private:
    void sortPoints(const QPointF& first, std::vector<QPointF>& pts);
    double pointDistance(const QPointF& lhs, const QPointF& rhs);
    void shortestPath(vector<QPointF>& path, const size_t s, const size_t f);
    int nearestPt(const QPointF& pt);
};
